package com.itheima.chanlin.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.chanlin.common.R;
import com.itheima.chanlin.entity.Member;
import com.itheima.chanlin.entity.Memberlog;
import com.itheima.chanlin.service.MemberlogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@RestController
@RequestMapping("/memberlog")
public class MemberlogController {

    @Autowired
    private MemberlogService memberlogService;

    /**
     * 员工信息分页查询
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @GetMapping("/page")
    public R<Page> page(int page, int pageSize, String name){
        log.info("page = {},pageSize = {},name = {}" ,page,pageSize,name);

        //构造分页构造器
        Page pageInfo = new Page(page,pageSize);

        //构造条件构造器
        LambdaQueryWrapper<Memberlog> queryWrapper = new LambdaQueryWrapper();
        //添加过滤条件
        queryWrapper.like(StringUtils.isNotEmpty(name),Memberlog::getName,name);
        //添加排序条件
        queryWrapper.orderByDesc(Memberlog::getCreateTime);

        //执行查询
        memberlogService.page(pageInfo,queryWrapper);

        return R.success(pageInfo);
    }



}
